var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var Item_Bag_EquipItem_UIBindings = require("AA_Item_Bag_EquipItem_UIBindings");
var ResKeeper = require("AA_ResKeeper");
var Const_Hall = require("AA_Const_Hall");
var PlayerDataManager = require("AA_PlayerDataManager");
var Excel = require("AA_Excel");
var BundleConfig = require("AA_BundleConfig");
var CommonUtils = require("AA_CommonUtils");
var UIManager = require("AA_UIManager");
var UIConfig_Home = require("AA_UIConfig_Home");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_Item_Bag_EquipItem = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.spriteMaterial = [];
    t.isShowExp = false;
    t.miaoBianColor = [new cc.Color(5, 140, 65, 255), new cc.Color(32, 71, 131, 255), new cc.Color(126, 33, 164, 255)];
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.onLoad = function () {
    this.auto_ui.addClickListener(this._clickListener, this);
  };
  _creator.prototype._clickListener = function (e) {
    switch (e) {
      case this.auto_ui.btn_infoBtn:
        this.OpenInfo();
    }
  };
  _creator.prototype.OpenInfo = function (e) {
    undefined === e && (e = false);
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_EquipInfo, {
      openData: this.openData,
      upLevelReset: this.ResetThis.bind(this),
      isAiDressUp: e
    });
  };
  _creator.prototype.ResetThis = function () {
    this.StartSet(this.openData);
  };
  _creator.prototype.SetCanClick = function (e) {
    this.auto_ui.btn_infoBtn.node.active = e;
  };
  _creator.prototype.onEnable = function () {
    this.isShowExp && this.ResetLevelAndExp();
  };
  _creator.prototype.StartSet = function (e, t, o) {
    undefined === t && (t = true);
    undefined === o && (o = true);
    this.SetCanClick(t);
    this.openData = e;
    var n = this.auto_ui;
    this.node.children[0].active = 0 != e.unLockChar;
    this.node.children[1].active = 0 == e.unLockChar && 0 == e.shuiGuoId;
    this.node.children[2].active = 0 == e.unLockChar && 0 != e.shuiGuoId;
    if (0 != e.unLockChar) {
      n.txt_unLockInfo.string = "通关章节" + e.unLockChar + "解锁";
    } else if (0 == e.unLockChar && 0 != e.shuiGuoId) {
      var i = Excel.Excel.shuiguo(e.shuiGuoId);
      n.txt_nameLabel.string = i.name;
      var a = PlayerDataManager.PlayerDataMgr.GetEquipDataById(e.shuiGuoId);
      var r = a && a.isUnLock;
      this.LoadSprite(i.id);
      if (o) {
        this.SetAllChildIsGray(!r);
      } else {
        this.SetAllChildIsGray(false);
      }
      Excel.Excel.bagEquipRule_all.forEach(function (t) {
        t.shuiguoId == e.shuiGuoId && n.node_geZiFather.children.forEach(function (e) {
          e.active = e.name == t.pfbName;
        });
      });
      n.node_bgFather.children.forEach(function (e, t) {
        e.active = t == i.quality - 1;
      });
      n.node_tiaoFather.children.forEach(function (e, t) {
        e.active = t == i.quality - 1;
      });
      if (r) {
        this.ResetLevelAndExp();
      } else {
        n.txt_lockLabel.string = "通过章节" + i.unLock + "解锁";
        n.txt_levelLabel.string = "";
        n.node_bgFather.children[3].active = true;
      }
      n.txt_lockLabel.node.active = !r;
      n.node_tiaoFather.active = r;
      n.node_unLockView.active = r;
    }
  };
  _creator.prototype.LoadSprite = function (e) {
    return __awaiter(this, undefined, undefined, function () {
      var t = this;
      return __generator(this, function () {
        this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/player" + (e - 1e3) + "_1", cc.SpriteFrame).then(function (e) {
          t.auto_ui.sp_iconSprite.spriteFrame = e;
          CommonUtils.default.LimitSpriteMaxSize(t.auto_ui.sp_iconSprite, Const_Hall.equipIconSize);
        });
        return [2];
      });
    });
  };
  _creator.prototype.SetAllChildIsGray = function (e) {
    var t = this;
    var o = this.node.children[2].getComponentsInChildren(cc.Sprite);
    var n = this.node.children[2].getComponentsInChildren(cc.Label);
    o.forEach(function (o) {
      "4" != o.name && o.setMaterial(0, e ? t.spriteMaterial[1] : t.spriteMaterial[0]);
    });
    n.forEach(function (o) {
      o.setMaterial(0, e ? t.spriteMaterial[1] : t.spriteMaterial[0]);
    });
  };
  _creator.prototype.ResetLevelAndExp = function () {
    this.isShowExp = true;
    var e = this.openData;
    var t = this.auto_ui;
    if (!(e.shuiGuoId < 1e3)) {
      var o = PlayerDataManager.PlayerDataMgr.GetEquipDataById(e.shuiGuoId);
      t.txt_levelLabel.string = "等级" + o.level;
      if (o.level > e.upLevelDatas.length) {
        t.txt_expLabel.string = o.fragments + "/MAX";
        t.progress_expBar.progress = 1;
        t.node_expIconFather.children[0].active = true;
        t.node_expIconFather.children[1].stopAllActions();
        t.node_expIconFather.children[1].active = false;
      } else {
        var n = e.upLevelDatas[o.level - 1];
        t.txt_expLabel.string = o.fragments + "/" + n.shengjixiaohao;
        var i = o.fragments / n.shengjixiaohao;
        t.progress_expBar.progress = i;
        t.progress_expBar.progress <= 0 && (t.progress_expBar.progress = .05);
        t.progress_expBar.node.children[0].children[0].opacity = i < 1 ? 255 : 0;
        t.progress_expBar.node.children[0].children[1].opacity = i >= 1 ? 255 : 0;
        t.node_expIconFather.children[0].active = i < 1;
        t.node_expIconFather.children[1].active = i >= 1;
        if (i >= 1) {
          t.node_expIconFather.children[1].stopAllActions();
          t.node_expIconFather.children[1].runAction(cc.repeatForever(cc.sequence(cc.moveTo(.5, 0, 15), cc.moveTo(.5, 0, 0))));
        }
      }
    }
  };
  _creator.prototype.GetCanUp = function () {
    var e = PlayerDataManager.PlayerDataMgr.GetEquipDataById(this.openData.shuiGuoId);
    if (e.level <= this.openData.upLevelDatas.length) {
      var t = this.openData.upLevelDatas[e.level - 1];
      var o = this.openData.upLevelDatas[e.level - 1];
      if (e.fragments >= t.shengjixiaohao && PlayerDataManager.PlayerDataMgr.globalData.gold >= o.money) {
        return true;
      }
    }
    return false;
  };
  __decorate([_property(Item_Bag_EquipItem_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  __decorate([_property([cc.Material])], _creator.prototype, "spriteMaterial", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_Item_Bag_EquipItem;